package reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Test2 {
    public static void main(String[] args) throws Exception {
        Class c=Class.forName("reflect.Person");
        Method[] methods1=c.getDeclaredMethods();
        Object obj=c.newInstance();
        for(Method m:methods1) {
            System.out.print(m.getName()+" ");
        }
        Method[] methods2=c.getMethods();
        for (Method m:methods2){
            if (m.getParameterCount()==0 && m.getModifiers()== Modifier.PUBLIC){
                System.out.println("调用方法"+m.getName());
                m.invoke(obj);
            }
        }
    }
}
